﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccess
{
    public class DataAccessClient
    {
        public static List<Model.Client> SearchClientById(Model.Client clientFind)
        {
            SSDDEntities.Instance.DiscardChanges();
            return (from q in SSDDEntities.Instance.Clients
                    where q.ClientId == clientFind.ClientId
                    select q).ToList();
        }

        public static void InsertNewClient(Model.Client newClient)
        {
            SSDDEntities.Instance.Clients.Add(newClient);
            SSDDEntities.Instance.SaveChanges();
        }

        public static void UpdateClient(Model.Client newClient)
        {
            SSDDEntities.Instance.DiscardChanges();
            var p = (from q in SSDDEntities.Instance.Clients
                    where q.ClientId == newClient.ClientId
                    select q).First();
            p.ClientAddress = newClient.ClientAddress;
            p.ClientName = newClient.ClientName;
            p.ClientPhone = newClient.ClientPhone;
            SSDDEntities.Instance.SaveChanges();
        }
    }
}
